package com.ruihu.admin.module.business.electric.config.domain.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruihu.admin.common.domain.BaseEntity;
import com.ruihu.admin.module.business.electric.config.domain.dto.ElectricConfigAddDTO;
import com.ruihu.admin.module.business.electric.config.domain.dto.ElectricConfigDTO;
import com.ruihu.admin.module.business.electric.config.domain.dto.ElectricConfigUpdateDTO;
import lombok.Data;
import java.util.Objects;

/**
 * [ 电芯型号维护表 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-12-28 12:14:15
 * @since JDK1.8
 */

@Data
@TableName("t_electric_config")
public class ElectricConfigEntity extends BaseEntity {


    /**
     * 电芯编码
     */
    private String code;

    /**
     * 电芯类型
     */
    private String type;

    /**
     * 描述
     */
    private String remark;

    /**
     * 配置类型
     */
    private Integer configType;

    /**
     * 创建人
     */
    private Long creator;

    /**
     * 更新人
     */
    private Long updater;

    public static ElectricConfigEntity convertToElectricConfigEntity(ElectricConfigAddDTO addDTO) {
        if (addDTO == null) {
            return null;
        }

        ElectricConfigEntity entity = new ElectricConfigEntity();
        entity.setCode(addDTO.getCode());
        entity.setType(addDTO.getType());
        entity.setRemark(addDTO.getRemark());
        entity.setCreator(addDTO.getCreator());
        entity.setUpdater(addDTO.getUpdater());
        return entity;
    }


    public static ElectricConfigEntity convertToElectricConfigEntity(ElectricConfigUpdateDTO updateDTO) {
        if (updateDTO == null) {
           return null;
        }

        ElectricConfigEntity entity = new ElectricConfigEntity();
        entity.setId(updateDTO.getId());
        entity.setCode(updateDTO.getCode());
        entity.setType(updateDTO.getType());
        entity.setRemark(updateDTO.getRemark());
        entity.setCreator(updateDTO.getCreator());
        entity.setUpdater(updateDTO.getUpdater());
        return entity;
    }

    public static ElectricConfigEntity convertToElectricConfigEntity(ElectricConfigDTO dto) {
        if (dto == null) {
           return null;
        }

        ElectricConfigEntity entity = new ElectricConfigEntity();
        entity.setId(dto.getId());
        entity.setCode(dto.getCode());
        entity.setType(dto.getType());
        entity.setRemark(dto.getRemark());
        entity.setCreateTime(dto.getCreateTime());
        entity.setUpdateTime(dto.getUpdateTime());
        entity.setCreator(dto.getCreator());
        entity.setUpdater(dto.getUpdater());
        return entity;
    }

    public static ElectricConfigEntity copyIgnoreNullAndEmpty(ElectricConfigEntity sourceEntity, ElectricConfigEntity destEntity) {
        if (Objects.isNull(sourceEntity))
            return destEntity;
        if (Objects.nonNull(sourceEntity.getId())) {
           destEntity.setId(sourceEntity.getId());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getCode())) {
           destEntity.setCode(sourceEntity.getCode());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getType())) {
           destEntity.setType(sourceEntity.getType());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getRemark())) {
           destEntity.setRemark(sourceEntity.getRemark());
        }
        if (Objects.nonNull(sourceEntity.getCreateTime())) {
           destEntity.setCreateTime(sourceEntity.getCreateTime());
        }
        if (Objects.nonNull(sourceEntity.getUpdateTime())) {
           destEntity.setUpdateTime(sourceEntity.getUpdateTime());
        }
        if (Objects.nonNull(sourceEntity.getCreator())) {
           destEntity.setCreator(sourceEntity.getCreator());
        }
        if (Objects.nonNull(sourceEntity.getUpdater())) {
           destEntity.setUpdater(sourceEntity.getUpdater());
        }
        return destEntity;
    }
}
